package com.northwind.controller;

import com.northwind.entity.Category;
import com.northwind.service.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;

@Controller
@RequestMapping("category")
public class CategoryController {
    @Resource
    CategoryService categoryService;

    @ResponseBody
    @RequestMapping("queryByPage")
    public HashMap<String, Object> queryAllPage(Integer page, Integer rows) {
        return categoryService.queryAllPage(page, rows);
    }

    @ResponseBody
    @RequestMapping("edit")
    public void edit(Category category,String oper){
        if (oper.equals("add")){
            categoryService.add(category);
        }
        if (oper.equals("edit")){
            categoryService.update(category);
        }
        if (oper.equals("del")){
            categoryService.delete(category);
        }
    }
    @ResponseBody
    @RequestMapping("queryByTwoCategory")
    public HashMap<String, Object> queryByTwoCategory(Integer page, Integer rows,String parentId) {
        return categoryService.queryByTwoCategory(page, rows, parentId);
    }
}
